package com.haelth.control;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import javax.swing.JTextArea;

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import com.haelth.comman.Connectchawa;
import com.haelth.comman.basic.BaseQuery;
import com.haelth.models.medicinedata.Medicine;

public class ChahwaGetQuery extends BaseQuery<Medicine> implements Runnable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int count;
	private String drug;
	private String hid;

	public String getHid() {
		return hid;
	}

	public void setHid(String hid) {
		this.hid = hid;
	}

	public ChahwaGetQuery() {
		super();
	}

	public void setResault(JTextArea resault) {
		Resault = resault;
	}

	public String getDrug() {
		return drug;
	}

	public void setDrug(String drug) {
		this.drug = drug;
	}

	public void findQuery() throws IOException {
		cookies = new Connectchawa().Connect();

		doc = Jsoup
				.connect(
						"https://www.chahwa.com.tw/order.php?act=query&&"
								+ "drug=" + drug + "&hid=" + hid)
				.cookies(cookies).get();

		
		System.out.println();
		Resault.append(doc.getAllElements().text());
		dispose();

	}

	public void run() {

		try {
			findQuery();
		} catch (IOException e) {
			// TODO 自動產生的 catch 區塊
			e.printStackTrace();
		}

	}
}
